<?php

namespace app\uniapp\controller;

use app\common\exception\MiException;
use app\Request;
use app\uniapp\service\DiyService;
use app\uniapp\service\GoodsCateService;
use app\uniapp\service\SiteService;
use app\uniapp\service\UniReqService;
use app\uniapp\service\UserAddressService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;

class GoodsCateController extends UniController
{

    /**
     * 通过上级id查询所有下级分类
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws DataNotFoundException
     */
    public function list(Request $request): \think\response\Json
    {
        $pid = $request->param("pid", 0);
        $list = GoodsCateService::instance()->setWhere([
            ['pid', '=', $pid]
        ])
            ->select();

        return jsonSuccess([
            'items' => $list,
        ]);

    }

    /** 商品分类页样式
     * @param Request $request
     * @return Json
     */
    public function diyPage(Request $request): Json
    {
        $goodsCate = DiyService::instance()->getGoodsCatePage();
        return jsonSuccess([
            'info' => $goodsCate
        ]);
    }

}
